﻿@*model winproject.Models.GlobalViewModel*@
@using winproject.Models;
@{
    ViewBag.Title = "Category";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

    int resCode = 0;
    CategoryDetails oItemEditDetail = null;
    if (ViewData != null && ViewData.Keys.Count() > 0 && ViewData.Keys.Contains("resCode"))
    {
        resCode = Convert.ToInt32(ViewData["resCode"]);
    }
    if (resCode == 250)
    {
        oItemEditDetail = (CategoryDetails)ViewData["resData"];
    }
    
}


<link type="text/css" rel="stylesheet" href="~/Content/css/jquery-te-1.4.0.css">
<script type="text/javascript" src="~/Scripts/jquery-te-1.4.0.js" charset="utf-8"></script>

@Html.Partial("_LeftMenu")


<!-- content -->
<div class="col-md-10">
    
    <div class="row">
        <div class="panel panel-default bootstrap-admin-no-table-panel">
            <div class="panel-heading">
                <div class="text-muted bootstrap-admin-box-title">Category > Details</div>
            </div>
            <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                <form id="frmCategory" action="~/Admin/AddCategory"  method="post" enctype="multipart/form-data" >
                    @{
                        if (oItemEditDetail != null && (oItemEditDetail.nItemId) > 0)
                        {
                            <input type="hidden" id="txtUniqueId" name="txtUniqueId" value="@oItemEditDetail.nItemId" />
                        }
                          else{
                            <input type="hidden" id="txtUniqueId" name="txtUniqueId" value="0" />   
                        }
                     }
                <table width="100%"  cellpadding="5" class="table-striped">
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Category Name
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sItemName))
                                {
                                    <input type="text" id="txtCatName" name="txtCatName" value="@oItemEditDetail.sItemName.Trim()"/>
                                }
                                else{
                                    <input type="text" id="txtCatName" name="txtCatName" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Category Slug
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sItemSlug))
                                {
                                    <input type="text" id="txtCatSlug" name="txtCatSlug" value="@oItemEditDetail.sItemSlug.Trim()"/>
                                }
                                else{
                                    <input type="text" id="txtCatSlug" name="txtCatSlug" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top" >
                            Description
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td style="vertical-align:top">
                            <textarea id="txtCatDesc" name="txtCatDesc" class="jqte-test">
                                 @{
                                     if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sItemDescription))
                                    {
                                        @WebUtility.HtmlDecode(oItemEditDetail.sItemDescription)
                                    }
                                }
                            </textarea>

                        </td>
                    </tr>
                    
                    <tr>
                        <td colspan="2">
                            &nbsp;
                        </td>
                        <td class="text-left">
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.nItemId) > 0)
                                {
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Save">Save</button>
                                }
                                else{
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Add">Add</button>
                                }
                            }
                            &nbsp; &nbsp;
                            <button type="button" id="cmdCancel" name="cmdSave" value="Cancel" onclick="window.location.href='@HttpContext.Current.Request.ApplicationPath/Admin/Category'">Cancel</button>
                        </td>
                    </tr>
                </table>
                </form>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="panel panel-default bootstrap-admin-no-table-panel">
            <div class="panel-heading">
                <div class="text-muted bootstrap-admin-box-title">Category Listing</div>
            </div>
            <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                <div class="row">
                    <div class="col-md-12">
                        <table width="100%" cellpadding="5" cellspacing="0" class="table-striped">
                            <thead>
                                <th>Sr.No</th>
                                <th>Category Name</th>
                                <th>Slug</th>
                                <th>Description</th>
                                <th>Actions</th>
                            </thead>
                            <tbody id="list_info">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script type="text/html" id="tpl_listinfo">
    <tr id="info-{itemid}-item">
        <td>
            {srno}
        </td>
        <td>
            {name}
        </td>
        <td>
            {slug}
        </td>
        @*<td>
            <img src="{vimg}" height="35" alt="{vname}" title="{vname}"/>
        </td>*@
        <td>
            {desc}
        </td>
        <td>
            <a href="javascript:void(0)"  onclick="return editItem({itemid});">Edit</a>
            &nbsp;/&nbsp; 
            <a href="javascript:void(0)" class="del-action"  data-toggle="modal" data-target="#myModal"  onclick="return deleteItem({itemid},'cat-item');">Delete</a>
        </td>
    </tr>
</script>



<script>
    
    var oMycontentLoader = new MyContentLoader();
    //Declarations
    var itemGridListGlobal = [];
    
    

    function editItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            $("#txtUniqueId").val(itemid);
            $("#frmCategory").attr("action", approotpath+"Admin/Category");
            $("#frmCategory").submit();
        }
    }
    function deleteItem(itemid, targetitem) {
        if (confirm("Are you sure want to delete?")) {
            switch (targetitem) {
                case 'cat-item':
                    deleteCatItem(itemid);
                    break;
            }
        }
    }
    function deleteTargetItem(itemid, targetitem) {
        switch (targetitem) {
            case 'cat-item':
                deleteCatItem(itemid);
                break;
        }
    }

    function deleteCatItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            var oItemdetail = new CatDetails();
            oItemdetail.nItemId= itemid;
            $(document).ready(function () {
                $.ajax(approotpath+"Admin/DeleteCategory", {
                    data: oItemdetail,
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                        var dataJson = data;//$.parseJSON(data);
                        if (parseInt(dataJson.errCode) == 250) {
                            if (document.getElementById("info-" + itemid + "-item")) {
                                $("#info-" + itemid + "-item").remove();
                                if ($("#list_info").find("tr").length <= 0) {
                                    $("#list_info").append(oMycontentLoader.noRecordExist(5, "No More Records Exists"));
                                }
                                alert("Item removed");
                            }
                        }
                    }
                });
            });
        }
    }

    //get virus detail list on load time
    $(document).ready(function () {
        
        oMycontentLoader.showLoader("list_info", 5, true);
        $.ajax(approotpath + "Admin/GetCategoryDetailJson", {
            data: {},
            type: "GET",
            dataType: 'json',
            success: function (data) {
                var dataJson = $.parseJSON(data.msgJson);
                makeItemGrid(dataJson);
                //self.categories(mappedCategories);
            },
            error: function (jqXHR, status, err) {
                console.log("Error raised: " + err);
                $("#list_info").append(oMycontentLoader.noRecordExist(5, "Oop's Something went wrong..."));
            },
            complete: function (jqXHR, status) {
                oMycontentLoader.hideLoader(oMycontentLoader.LastAccessedContainerId);
            }
        });
    });
    

    //getVirusDetail():: fetches virus details
    function getCategoryDetail() {
        $.getJSON(approotpath + "Admin/GetCategoryDetailJson", function (response) {
            //alert(catResponse.errCode);
            if (response.errCode == 250) {
                return $.parseJSON(response.msgJson);
            }
            else {
                return [];
            }

        });
    }
    //makeVirusGrid():: Lists virus details
    function makeItemGrid(itemGridList) {

        if (itemGridList.length > 0) {
            itemGridListGlobal.push(itemGridList);
            if (document.getElementById("list_info")) {
                var info_template = $("#tpl_listinfo").html();
                var vcount = 0;
                var vdesc = "";
                for (vcount = 0; vcount < itemGridList.length; vcount++) {
                    vdesc = htmlDecode(itemGridList[vcount].sItemDescription);
                    $("#list_info").append(info_template.replace(/{srno}/g, (vcount + 1)).replace(/{name}/g, itemGridList[vcount].sItemName).replace(/{slug}/g, itemGridList[vcount].sItemSlug).replace(/{img}/g, getAppPath(itemGridList[vcount].sItemImagePath)).replace(/{desc}/g, vdesc).replace(/{itemid}/g, itemGridList[vcount].nItemId));
                }
                
            }
        }
        var ignoreRows = 0;
        if (document.getElementById("list_info" + "_loader")) {
            ignoreRows = 1;
        }
        if ($("#list_info").find("tr").length <= 0) {
            $("#list_info").append(oMycontentLoader.noRecordExist(5, "No More Records Exists"));
        }
    }

    
    

    $('.jqte-test').jqte();
	
	// settings of status
	var jqteStatus = true;
	$(".status").click(function()
	{
		jqteStatus = jqteStatus ? false : true;
		$('.jqte-test').jqte({"status" : jqteStatus})
	});

	
</script>
